package com.example07.entities;

import java.util.ArrayList;
import java.util.List;

public class Railways  {
    private static final List<Ticket> TICKETS = create();
    private static List<Ticket> create() {
        List<Ticket> tickets = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            tickets.add(new Ticket(i, "哈尔滨", "北京"));
        }
        return tickets;
    }
    public static List<Ticket> listTickers() {
        return TICKETS;
    }
    public Ticket sellTicket() {
        try {
            return listTickers().remove(0);
        } catch (IndexOutOfBoundsException e) {
            return null;
        }
    }
}
